package Memento_Pattern.Stack;

// -*-coding:utf-8 -*-
//人员：刘陆鑫
//班级：19软3
//学号；2019110218
public class Client {
    private static int index=-1;
    private static MementpCaretaker mementpCaretaker=new MementpCaretaker();

    public static void main(String[] args) {
        Obj obj=new Obj(1);
        play(obj);
        obj.setNum(2);
        play(obj);
        obj.setNum(3);
        play(obj);
        undo(obj,index);
        undo(obj,index);
        redo(obj,index);
        redo(obj,index);
    }
    public static void play(Obj obj){
        mementpCaretaker.setMementos(obj.save());
        index++;
        System.out.println("状态更新，当前状态为"+obj.getNum());
    }
    public static void undo(Obj obj,int i){
        System.out.println("撤销");
        index--;
        obj.restore(mementpCaretaker.getMementos(i-1));
        System.out.println("状态为"+obj.getNum());
    }
    public static void redo(Obj obj,int i){
        System.out.println("重来");
        index++;
        obj.restore(mementpCaretaker.getMementos2(i));
        System.out.println("状态为"+obj.getNum());
    }
}
